/**
*  \file gpio.h
*
*  \brief
*
*  \authors Dajin Li  dajin.li@linde-.de
*
*
*
*/

#ifndef __MENU_H_
#define __MENU_H_


/*================================================[ public includes  ]================================================*/
#include "stm32f10x.h"
#include "global.h"
#include "top.h"
#include "var_tbl.h"

/*================================================[ public datatypes ]================================================*/


/*================================================[ inline functions ]================================================*/


/*================================================[ public defines   ]================================================*/
#define ACTIVE_FIRST_PAGE_MAX_LINE_NO  		    (4)
#define STORED_FIRST_PAGE_MAX_LINE_NO  		    (3)
#define KM_TO_MPH                               6214 / 10000
#define MPH_TO_KM                               10000 / 6214


// language type
#define EN_LAN                                  0
#define CHN_LAN                                 1
#define FRENCH_LAN                              2
#define SPN_LAN                                 3
#define CAL_TIMEOUT_MAX                         50             // timeout
#define MENU_TYPE_MASK                          0x000F         // menu type
#define MENU_TYPE0                              0              //default menu
#define MENU_TYPE1                              1              //error menu
#define MENU_DATA_TYPE                          0x8000         //special menu, none date-mode
#define MENU_ACCESS                             0x4000         //access menu
#define MENU_ACCESS_LEVEL_MASK                  0x3000         //menu access level

#define MENU_ACCESS_LEVEL0                      0x0000         //menu access level0 -tech login
#define MENU_ACCESS_LEVEL1                      0x1000         //menu access level1- service login

#define MENU_ACC0                               0x0000         // access any level, can be access by technician, and service
#define MENU_ACC1                               0x1000         // access level 1, can any access by only service,


// Rtc 
#define RTC_SET_SECONDS                         1
#define RTC_SET_MINUTES                         2
#define RTC_SET_HOURS                           3
#define RTC_SET_YEARS                           4
#define RTC_SET_MONTH                           5
#define RTC_SET_DATE                            6
#define RTC_SET_PM                              7
#define RTC_SET_HOUR_FORMAT                     8
#define MENU_CLEAR_WIDTH                        200
                                                
// limit value                                  
#define MAX_TRACTION_SPD_KMH                    250
#define MIN_TRACTION_SPD_KMH                    0

#define MAX_ID_SYSTEM_SPD_KMH                   40
#define MIN_ID_SYSTEM_SPD_KMH                   1


#define MAX_TRACTION_SPD_MPH                    160
#define MIN_TRACTION_SPD_MPH                    0

#define MAX_ID_SYSTEM_SPD_MPH                   25
#define MIN_ID_SYSTEM_SPD_MPH                   1

#define MAX_MAINTENANCE_DAYS                    1000
#define MAX_MAINTENANCE_HOURS                   5000


// lcd display type
#define INVERT_VALUE                            3
#define NOT_INVERT_VALUE                        2
#define NOT_FLASHING_VALUE                      4
#define FLASHING_VALUE                          5

#define KPA_TO_PSI                              145/1000
#define LINE_OFFSET_20                          21
#define LINE5_OFFSET_20                         32
#define LINE6_OFFSET_20                         27
#define DIAG_ROW_OFFSET1		                95
#define MENU_BACK_GRAY                          0xff



#define SEATBELT_GRAPHICAL                      BIT0
#define REVERSE_GRAPHICAL                       BIT1
#define FORWARD_GRAPHICAL                       BIT2
#define NEUTRAL_GRAPHICAL                       BIT3
#define DESCENTING_GRAPHICAL                    BIT4
#define FITER_PRESSURE_HIGH_GRAPHICAL           BIT5
#define CREEP_MODE_GRAPHICAL                    BIT6
#define PARKING_SET_GRAPHICAL                   BIT7
#define DIRECTION_GRAPHICAL                     BIT8
#define SERVICE_GRAPHICAL                       BIT9
#define REVERSE_WARN_GRAPHICAL                  BIT10
#define LEFT_TURN_GRAPHICAL                     BIT11
#define RIGHT_TURN_GRAPHICAL                    BIT12
#define FWD_DIR_GRAPHICAL                       BIT13
#define REV_DIR_GRAPHICAL                       BIT14
#define NEUTRAL_DIR_GRAPHICAL                   BIT15
#define ASSIST_GRAPHICAL                        BIT16
#define BOOT_LIFT_CTRL_GRAPHICAL                BIT17
#define CHARGE_BAT_FIN_GRAPHICAL                BIT18
#define LIFT_HEIGHT_GRAPHICAL                   BIT19

#ifdef S1D19600
// position
#define ERROR_ROW_OFFSET                        33
#define CAL_ROW_OFFSET                          33
#define DRAW_LINE_FAC                           4
#define INFO_COL_OFFSET                         16
#define NO_ICON_ROW_OFFSET                      32
#define ENG_ROW_OFFSET                          50
#define ERROR_COL_OFFSET_1                      62
#define CAL_COL_OFFSET                          62
#define LINE_OFFSET                             27
#define LINE_OFFSET_1                           30
#define VALUE_COL_OFFSET                        120
#endif


#ifdef ST7511
// position
#define ERROR_ROW_OFFSET                        33
#define CAL_ROW_OFFSET                          33

#define DRAW_LINE_FAC                           4
#define INFO_COL_OFFSET                         16
#define NO_ICON_ROW_OFFSET                      37
#define ENG_ROW_OFFSET                          50
#define ERROR_COL_OFFSET_1                      222
#define CAL_COL_OFFSET                          222

#define LINE_OFFSET                             27
#define LINE_OFFSET_1                           30
#define VALUE_COL_OFFSET                        280
#endif


#define TRAC_CODE                               3
#define PUMP_CODE                               4
#define BMS_CODE                                5
#define RFID_CODE                               6


#define CELSIUS_TO_FAHRENHEIT( CELSIUS )        (9.0 / 5) * CELSIUS + 32
#define FAHRENHEIT_TOCELSIUS( FAHRENHEIT )      (FAHRENHEIT - 32) / (9.0 / 5)
/*================================================[ public variables ]================================================*/
extern u8 key_serviced;

extern u8 date_format;   // 12/31/2015, or 2015/12/31 or 31/12/2015
extern u8 date_format_data;
extern u8 date_hours;
extern u8 date_minutes;
extern u8 date_seconds;
extern u8 hour_format_12H;
extern u8 date_am;              // to display am or pm
extern u8 enClearMenu;

/* Store the current day of the week.
values are valid from 0 to 6*/
extern u8 date_day;
extern u8 seatBelt;
extern u8 seatBeltData;

extern u8 date_month;
extern u8 date_year;
extern u8 date_week;
extern u8 set_time_flag;
extern u8 regulate_time_flag;

extern s8 menu_needs_ee;
extern s16 menu_ee_index;
extern s16 max_traction_speed_forw_value;
extern s16 max_traction_speed_forw_data;

extern s16 max_traction_speed_forw_value_request;

extern s16 max_traction_speed_back_value;
extern s16 max_traction_speed_back_data;
extern s16 max_traction_speed_back_value_request;
extern s16 max_traction_speed_forw_kwp;
extern s16 max_traction_speed_back_kwp;


extern s16 safety_speed_value;
extern s16 safety_speed_data;

extern s16 area_back_speed_dly_value;
extern s16 area_back_speed_dly_data;

extern s16 accel_decel;  // for area speed control
extern s16 rfid_timeout;
extern s16 accel_decel_data;  // for area speed control
extern s16 rfid_timeout_data;
extern u8 lcd_bklight_data;

extern s16 max_engine_speed_value;
extern s16 max_traction_speed_kp;
extern s16 max_traction_speed_kp_data;
extern s16 max_traction_speed_ki;
extern s16 max_traction_speed_ki_data;
extern s16 max_traction_speed_kd ;
extern s16 max_traction_speed_kd_data;

extern s16 act_max_engine_speed_value;
extern s16 min_engine_speed_value;
extern u16 pin_code[];
extern enum var_tbl_disp_options display_options;
extern enum var_tbl_disp_options display_options_data;
extern u8 fuel_sensor_type;
extern u8 fuel_sensor_type_data;
extern u16 creep_speed;
extern u16 creep_speed_data;


extern s16 service_hours1;
extern s16 service_hours2;
extern s16 service_hours3;
extern s16 service_hours4;

extern s16 service_days1;
extern s16 service_days2;
extern s16 service_days3;
extern s16 service_days4;

extern s16 temp_key_vector;
extern u16 speedometer_units_data;      // 0: km 1: miles
extern u8 LanguageSelect_data;
extern s8 status_select1;
extern s8 status_select2;

extern s8 status_select1_data;
extern s8 status_select2_data;
extern u8 clearScreen;
extern u16 CANopen_clearScreen;
extern u8 J1939_clearScreen;
extern u16 lcd_bklight_pwm;

extern u16 br1347_trac_total_stored_fault;
extern u16 br1347_lift_total_stored_fault;
extern u16 display_active_fault_code[];
extern u8 display_active_fault_index;
extern u16 br1275_bms_total_stored_fault;
extern u16 rfid_total_stored_fault;


extern struct sMenu DisplayErrorCodesMenu;
extern struct sMenu ChangePWDMenu;
extern struct sMenu DisplaySettingMenu;

extern u8 data_mode;
extern u8 error_display;
extern u16 br1219_engine_total_stored_fault;
extern u8 fault_msg_disp_buffer[];
extern u8 restore_state;
extern u32 pre_can_obj_id;
extern u32 cur_can_obj_id;

extern s16 points1_volts_data;  // for area speed control
extern s16 points2_volts_data;  // for area speed control
extern s16 points3_volts_data;  // for area speed control

extern s16 points1_volts_value;  // for area speed control
extern s16 points2_volts_value;  // for area speed control
extern s16 points3_volts_value;  // for area speed control
extern s16 reverse_speed_value;
extern s16 reverse_speed_data;

extern s16 points1_distance_data;  // distance
extern s16 points2_distance_data;  // distance
extern s16 points3_distance_data;  // distance

extern s16 points1_distance_value;  // distance
extern s16 points2_distance_value; // distance
extern s16 points3_distance_value;  // distance
extern u8 show_distance_enable;
extern u8 reverse_distance_disp_flag;



extern struct sMenu EngOilMenu;
extern struct sMenu AirFilterMenu;
extern struct sMenu ServiceEngMenu;
extern struct sMenu ServiceMachineMenu;

extern struct sMenu keyonHoursMenu;
extern struct sMenu SeatHoursMenu;
extern struct sMenu EngineHoursMenu;
extern struct sMenu OnoffOptionsMenu;
extern E_STORED_FAULT_PARAM display_stored_fault[];
extern u8 dispError;
extern u8 MenuItemIndex;
extern u8 nMenuLevel;
extern u8 data_mode;
extern u8 LineIndex;
extern u16 pin_enable;


#endif
/***********************************************************************************************************************
*                             Copyright 2016 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/


